package com.service.actions;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.hibernate.HibernateException;

import com.service.hibernate.dao.GenericDAO;
import com.service.hibernate.dao.ServicesDAO;
import com.service.hibernate.dao.StockViewDAO;
import com.service.hibernate.dao.VehicleDAO;
import com.service.hibernate.pojos.Services;
import com.service.hibernate.pojos.Stocks;
import com.service.hibernate.pojos.Vehicles;

@SuppressWarnings("serial")
public class ServicesAction extends GenericAction<Services> {

	Services service = new Services();
	List<Services> services = new ArrayList<Services>();

	List<String> vehIds = new ArrayList<String>();

	private String vehicleId;

	GenericDAO<Services> servicesDAO = new ServicesDAO();
	GenericDAO<Stocks> stockViewDAO = new StockViewDAO();
	VehicleDAO vehiclesDAO = new VehicleDAO();

	public ServicesAction() {
		//vehIds = vehiclesDAO.getVehicleIds();

		vehIds.add("300-3658"); vehIds.add("253-2569"); vehIds.add("56-8965");vehIds.add("65-6589");vehIds.add("65-9856");

	}

	@Override
	public Services getModel() {
		return service;
	}

	public String execute() {
		try {
			service.setServiceDate(new Date());
			service.setStatus("On going");

			Vehicles vehicle = new Vehicles();
			vehicle.setVehRegNo(this.getVehicleId());
			service.setVehicle(vehicle);

			// Testing Purpose Only////////
			/*
			 * List<Stocks> items=new ArrayList<Stocks>(); items.add(new
			 * Stocks("1","Brake Oil","SAE 35",450f,400f,30)); items.add(new
			 * Stocks("2","Brake Oil","SAE 35",450f,400f,30));
			 * service.setItems(items);
			 */
			// ////////////////////////////

			System.out
					.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
			System.out.println("In execute...., EMP SID : "
					+ service.getServiceId() + " EMP KM : "
					+ service.getKilometers() + " ST : "
					+ service.getServiceType() + " VID : "
					+ this.getVehicleId() + " DATE : "
					+ service.getServiceDate());
			System.out
					.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
			// servicesDAO.addServices(service);
			servicesDAO.addData(service);
			return SUCCESS;
		} catch (HibernateException e) {
			return ERROR;
		}

	}

	public String listServices() {
		try {
			// services = servicesDAO.getServices();
			services = servicesDAO.getAllData("Services");
			return SUCCESS;
		} catch (HibernateException e) {
			return ERROR;
		}

	}

	public Services getService() {
		return service;
	}

	public void setService(Services service) {
		this.service = service;
	}

	public List<Services> getServices() {
		return services;
	}

	public void setServices(List<Services> services) {
		this.services = services;
	}

	public String getVehicleId() {
		return vehicleId;
	}

	public void setVehicleId(String vehicleId) {
		this.vehicleId = vehicleId;
	}

	public List<String> getVehIds() {
		return vehIds;
	}

	public void setVehIds(List<String> vehIds) {
		this.vehIds = vehIds;
	}

}
